const app = getApp()
Page({
  data: {
      datamsg: false,              
      tokenID: '',                     
      page: 1,                       
      moment: [],                   
  },
  onLoad:function(){
      var _this = this;
      _this.setData({
          tokenID: app.data.tokenID
      })
      _this.onReachBottom();
  },
  onPullDownRefresh: function () {
      var _this = this;
      this.setData({
          page: 1
      })
      wx.showNavigationBarLoading();
      _this.gtemomentList("down")
  },
  onReachBottom: function () {
      var that = this;
      wx.showLoading({
          title: '玩命加载中',
      })
      that.gtemomentList("up")
  },
  gtemomentList: function (type) {
      var that = this;
      that.setData({
          tokenID: app.data.tokenID
      })
      wx.request({
          url: app.data.api + 'coursepackage/getCoursePackagePage',
          data: {
              "page": that.data.page,
              "token": that.data.tokenID
          },
          method: "POST",
          header: { 'content-type': 'application/x-www-form-urlencoded' },
          success: function (res) {
              if (res.data.status) {
                  if (type == 'up') {
                      var moment_list = that.data.moment;
                      for (var i = 0; i < res.data.data.list.length; i++) {
                          moment_list.push(res.data.data.list[i]);
                      }
                      if (res.data.data.list.length == 0) {
                          that.setData({
                              datamsg: true
                          })
                      }
                      that.setData({
                          page: that.data.page + 1,
                          moment: that.data.moment
                      })
                  } else {
                      var moment_list = [];
                      for (var i = 0; i < res.data.data.list.length; i++) {
                          moment_list.push(res.data.data.list[i]);
                      }
                      that.setData({
                          page: that.data.page + 1,
                          moment: moment_list
                      })
                      wx.stopPullDownRefresh();
                  }
                  wx.hideLoading();
                  wx.hideNavigationBarLoading();
              } else {
                  wx.hideLoading();
                  wx.showModal({
                      title: '提示',
                      content: res.data.msg,
                      success: function (res) {
                          if (res.confirm) {
                              wx.redirectTo({
                                  url: '../login/login'
                              })
                          } else if (res.cancel) {
                              wx.redirectTo({
                                  url: '../login/login'
                              })
                          }
                      }
                  });
              }
          }
      })
  }
})